﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DuJianliang.ApplicationPlatform.Proj5715.Process
{
    public partial class ProcessExchangePartEdit : System.Web.UI.Page
    {
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ViewState["DispatchMissileProcessID"] = Request.QueryString["DispatchMissileProcessID"].Trim();

                if (Request.QueryString["ID"] != null)
                {
                    ViewState["ID"] = Request.QueryString["ID"].Trim();
                    var dal = new ProcessDal();

                    ExchangePartOB obj = dal.GetExchangePartObById(ViewState["ID"].ToString());
                    if (obj != null)
                    {
                        txt_S_DispatchCode.Text = obj.Source_DispatchCode;
                        txt_S_MissileCode.Text  = obj.Source_MissileCode;
                        txt_S_Team.Text         = obj.Source_WorkTeam;
                        txt_S_PartCode.Text     = obj.Source_PartCode;
                        txt_S_PartNum.Text      = obj.Source_PartNumber;
                        txt_T_DispatchCode.Text = obj.Targe_DispatchCode;
                        txt_T_MissileCode.Text  = obj.Targe_MissileCode;
                        txt_T_Team.Text         = obj.Targe_WorkTeam;
                        txt_T_PartCode.Text     = obj.Targe_PartCode;
                        txt_T_PartNum.Text      = obj.Targe_PartNumber;
                    }


                }

            }
        }

        protected void btn_OK_Click(object sender, EventArgs e)
        {
            string Source_DispatchCode = txt_S_DispatchCode.Text.Trim();
            string Source_MissileCode  = txt_S_MissileCode.Text.Trim();
            string Source_WorkTeam     = txt_S_Team.Text.Trim();
            string Source_PartCode     = txt_S_PartCode.Text.Trim();
            string Source_PartNumber   = txt_S_PartNum.Text.Trim();
            string Targe_DispatchCode  = txt_T_DispatchCode.Text.Trim();
            string Targe_MissileCode   = txt_T_MissileCode.Text.Trim();
            string Targe_WorkTeam      = txt_T_Team.Text.Trim();
            string Targe_PartCode      = txt_T_PartCode.Text.Trim();
            string Targe_PartNumber    = txt_T_PartNum.Text.Trim();

            ExchangePartOB obj = new ExchangePartOB();
            
            obj.DispatchMissileProcessRouteID = ViewState["DispatchMissileProcessID"].ToString();
            obj.Source_DispatchCode = Source_DispatchCode;
            obj.Source_MissileCode = Source_MissileCode;
            obj.Source_PartCode = Source_PartCode;
            obj.Source_PartNumber = Source_PartNumber;
            obj.Source_WorkTeam = Source_WorkTeam;

            obj.Targe_DispatchCode = Targe_DispatchCode;
            obj.Targe_MissileCode = Targe_MissileCode;
            obj.Targe_WorkTeam = Targe_WorkTeam;
            obj.Targe_PartCode = Targe_PartCode;
            obj.Targe_PartNumber = Targe_PartNumber;
            obj.ExchangeDate = DateTime.Now;

            try
            {
                var dal = new ProcessDal();
                if (ViewState["ID"] != null)
                {
                    obj.ExchangePartID = ViewState["ID"].ToString();
                    dal.ExchangePartOB_Update(obj);
                }
                else
                {
                    obj.ExchangePartID = Guid.NewGuid().ToString();
                    dal.ExchangePartOB_Insert(obj);
                }

                Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('保存成功');</script>"); 
                Response.Redirect("ProcessExchangePart.aspx?DispatchMissileProcessID=" + ViewState["DispatchMissileProcessID"].ToString());

            }
            catch
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('保存失败');</script>"); 
            }
        }

        protected void btn_Back_Click(object sender, EventArgs e)
        {
            Response.Redirect("ProcessExchangePart.aspx?DispatchMissileProcessID=" + ViewState["DispatchMissileProcessID"].ToString());
        }
    }
}